<?php
	class Model_order extends database{
		protected $_table = "donhang";
		protected $_table2 = "hoadonnhap";
		
		public function total_order(){
			$sql = "select * from $this->_table";
			$this->query($sql);
			return $this->num_rows();
		}
		public function list_order($start,$limit){
			$sql = "select * from $this->_table order by id DESC limit $start,$limit";
			$this->query($sql);
			return $this->fetchAll();
		}
		public function del_order($table,$id){
			$sql = "delete from $this->_table where id = '$id'";
			$this->query($sql);
		}
		public function get_order($id){
			$sql = "select *from $this->_table where id = '$id'";
			$this->query($sql);
			return $this->fetch();
		}
		//search
		public function search_total_order($from,$to){
			$sql = "SELECT * FROM $this->_table WHERE ngay_timkiem BETWEEN '$from' AND '$to'";
			//die($sql);
			$this->query($sql);
			return $this->num_rows();
		}
		public function search_list_order($from,$to,$start,$limit){
			$sql = "select * from $this->_table WHERE ngay_timkiem BETWEEN '$from' AND '$to' limit $start,$limit";
			$this->query($sql);
			return $this->fetchAll();
		}
		
		//menu
		public function total_order2(){
			$sql = "select * from $this->_table2";
			$this->query($sql);
			return $this->num_rows();
		}
		public function list_order2($start,$limit){
			$sql = "select * from $this->_table2 order by id DESC limit $start,$limit";
			$this->query($sql);
			return $this->fetchAll();
		}
		//search menu
		public function search_total_order2($from,$to){
			$sql = "SELECT * FROM $this->_table2 WHERE ngay_timkiem BETWEEN '$from' AND '$to'";
			$this->query($sql);
			return $this->num_rows();
		}
		public function search_list_order2($from,$to,$start,$limit){
			$sql = "select * from $this->_table2 WHERE ngay_timkiem BETWEEN '$from' AND '$to' limit $start,$limit";
			$this->query($sql);
			return $this->fetchAll();
		}
		public function get_order2($id){
			$sql = "select *from $this->_table2 where id = '$id'";
			$this->query($sql);
			return $this->fetch();
		}
		public function del_order2($table,$id){
			$sql = "delete from $this->_table2 where id = '$id'";
			$this->query($sql);
		}
	}
?>